
import { LoginApi } from '@/api/userapi'
import { getToken, setToken, delToken } from '@/utils/storage'
export default {
  state () {
    return {
      token: getToken(),
      userInfo: {}
    }
  },
  mutations: {
    changeToken (state, token) {
      state.token = token
    },
    resetToken (state) {
      state.token = null
      delToken()
    },
    setUser (state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    async login ({ commit }, ruleForm) {
      const res = await LoginApi(ruleForm)
      console.log(res)
      commit('changeToken', res.data.token)
      setToken(res.data.token)
    }
  },
  getters: {},
  namespaced: true
}